home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / system / geterror.zip / GETERROR.ASM < prev    next >
Assembly Source File  |  1987-08-01  |  6KB  |  174 lines

  1. page 55,132
  2. code segment
  3. assume cs:code,ds:code,es:code
  4. org 100h
  5. ;
  6. start:    jmp  initialize
  7. ; data area
  8. signature       db 'GETERROR.COM Version 1.00 by Brett Warthen'
  9. length_signature = $ - signature
  10. old_int21  dd ?
  11. old_int20  dd ?
  12. old_int16  dd ?
  13. error_code db 0
  14. ;
  15. ;-----------------------------------------------------------------------
  16. ; The following is our front-end to DOS, from which we will trap error
  17. ; codes issued by terminating programs.
  18. ;-----------------------------------------------------------------------
  19. ;
  20. new_int21:
  21.           cmp  ah,0                           ; change function 0 to
  22.           jnz  not_terminate_0                ;  4Ch with return code 0
  23.           mov  ax,4C00h
  24. not_terminate_0:
  25.           cmp  ah,4Ch                         ; not what we're lookin'
  26.           jnz  not_us                         ;  for...
  27.           mov  cs:error_code,al               ; here it is, save it!
  28.           jmp  do_it_dos
  29. not_us:
  30.           cmp  ah,31h
  31.           jnz  do_it_dos
  32.           mov  cs:error_code,al
  33. do_it_dos:
  34.           jmp  cs:old_int21                   ; back to old handler
  35. ;
  36. ;-----------------------------------------------------------------------
  37. ; The following is our Interrupt 20h handler, we translate it to
  38. ; Interrupt 21h, Function 4C, and terminate with return code 0
  39. ;-----------------------------------------------------------------------
  40. ;
  41. new_int20:
  42.           mov  ax,4C00h
  43.           int  21h
  44. ;
  45. ;-----------------------------------------------------------------------
  46. ; The following is our new Interrupt 16h handler.  We use it solely
  47. ;  for a signature request to make sure that we don't install more
  48. ;  than one copy of the program.
  49. ;-----------------------------------------------------------------------
  50. ;
  51. new_int16:
  52.           cmp  ax,0B0B1h                      ; sig request function
  53.           jz   signature_request
  54. NOTSIG:
  55.           jmp  cs:old_int16
  56.  
  57. signature_request:
  58.           push ds
  59.           push es
  60.           push si
  61.           push di
  62.           push cx
  63.  
  64.           push cs
  65.           pop  ds
  66.  
  67.           mov  di,offset signature
  68.           mov  cx,length_signature
  69.           repe cmpsb                          ; compare signatures
  70.           pop  cx
  71.           pop  di
  72.           pop  si
  73.           pop  es
  74.           pop  ds
  75.           jne  NOTSIG                         ; not ours
  76.           xchg al,ah                          ; ours -- swap AL & AH
  77.           push cs                             ; return pointer to
  78.           pop  ds                             ;  resident data seg in DS
  79.           iret
  80. ;
  81. ;-----------------------------------------------------------------------
  82. ; The following code is for installation purposes only and does not
  83. ;  remain resident.
  84. ;-----------------------------------------------------------------------
  85. ;
  86. initialize:
  87. ; check to see if already installed...
  88.           mov  ax,0B0B1h
  89.           mov  si,offset signature
  90.           int  16h
  91.  
  92.           cmp  ax,0B1B0h
  93.           jnz  not_installed
  94.  
  95.           mov  al,error_code                  ; DS points to resident
  96.           xor  ah,ah                          ;  data...
  97.  
  98.           push ds                             ; save that for later
  99.           push cs
  100.           pop  ds                             ; DS points local
  101.  
  102.           mov  dl,100                         ; convert code to ASCII
  103.           div  dl
  104.           cmp  al,0
  105.           jz   no_100s
  106.           add  al,'0'
  107.           mov  msg_code,al
  108. no_100s:
  109.           mov  al,ah
  110.           xor  ah,ah
  111.           mov  dl,10
  112.           div  dl
  113.           cmp  al,0
  114.           jz   no_10s
  115.           add  al,'0'
  116.           mov  msg_code[1],al
  117. no_10s:
  118.           add  ah,'0'
  119.           mov  msg_code[2],ah
  120.  
  121.           mov  ah,9                           ; display message
  122.           mov  dx,offset error_msg
  123.           int  21h
  124. ; restore pointer to resident data segment, and return with the same
  125. ;  error level so as to not effect DOS ERRORLEVEL statements in batch
  126. ;  files...
  127.           pop  ds
  128.           mov  ah,4Ch
  129.           mov  al,error_code
  130.           int  21h                            ; out of here!
  131.  
  132. not_installed:
  133.  
  134.           mov  ax,3521h                       ; Get address for old
  135.           int  21h                            ;  Int 21h routine
  136.           mov  word ptr old_int21,bx          ;  and save it
  137.           mov  word ptr old_int21[2],es
  138.  
  139.           mov  dx,offset new_int21            ; Set Int 21h to point to
  140.           mov  ax,2521h                       ;  our Int 21h handler
  141.           int  21h
  142.  
  143.           mov  ax,3520h                       ; Get address for old
  144.           int  21h                            ;  Int 20h routine
  145.           mov  word ptr old_int20,bx          ;  and save it
  146.           mov  word ptr old_int20[2],es
  147.  
  148.           mov  dx,offset new_int20            ; Set Int 20h to point to
  149.           mov  ax,2520h                       ;  our Int 20h handler
  150.           int  21h
  151.  
  152.           mov  ax,3516h                       ; Get address for old
  153.           int  21h                            ;  Int 16h routine
  154.           mov  word ptr old_int16,bx          ;  and save it
  155.           mov  word ptr old_int16[2],es
  156.  
  157.           mov  dx,offset new_int16            ; Set Int 16h to point to
  158.           mov  ax,2516h                       ;  our Int 16h handler
  159.           int  21h
  160.  
  161.           mov  ah,9                           ; Print installation
  162.           mov  dx,offset install_msg          ;  message
  163.           int  21h
  164.  
  165.           mov  dx,offset initialize           ; Terminate but remain
  166.           int  27h
  167.  
  168. install_msg  db 13,10,'GETERROR.COM Version 1.00 by Brett Warthen',13,10
  169.              db 'has been installed in RAM Memory.',13,10,13,10,'$'
  170. error_msg    db 13,10,'GETERROR:  Last Program terminated with Error Code '
  171. msg_code     db '000',13,10,'$'
  172. code ends
  173. end start
  174.